<!-- Sn Field -->
<div class="form-group col-sm-6">
    {!! Form::label('sn', '编号:') !!}
    {!! Form::text('sn', null, ['class' => 'form-control']) !!}
</div>

<div class="form-group col-sm-12">
    {!! Form::label('cat_id', '分类:') !!}
    @foreach($cats as $cat)
        @if($cat->slug=='all')
            {!! Form::checkbox('cat_id[]', $cat->id,true) !!} {{$cat->name}}
        @else
            {!! Form::checkbox('cat_id[]', $cat->id,isset($has_cat_ids)?(in_array($cat->id,$has_cat_ids)?true:false):false) !!} {{$cat->name}}
        @endif
    @endforeach
</div>

<!-- Name Field -->
<div class="form-group col-sm-6">
    {!! Form::label('name', '名称:') !!}
    {!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>

<div class="form-group col-sm-6">
    {!! Form::label('title', '名称补充:') !!}
    {!! Form::text('title', null, ['class' => 'form-control']) !!}
</div>

<!-- Click Count Field -->
<div class="form-group col-sm-6">
    {!! Form::label('click_count', '点击量:') !!}
    {!! Form::text('click_count', isset($goods)?$goods->click_count:0, ['class' => 'form-control']) !!}
</div>

<!-- Sales Count Field -->
<div class="form-group col-sm-6">
    {!! Form::label('sales_count', '销售量:') !!}
    {!! Form::text('sales_count', isset($goods)?$goods->sales_count:0, ['class' => 'form-control']) !!}
</div>

<!-- Brand Field -->
<div class="form-group col-sm-6">
    {!! Form::label('brand', '品牌:') !!}
    {!! Form::text('brand', null, ['class' => 'form-control']) !!}
</div>

<!-- Provider Name Field -->
<div class="form-group col-sm-6">
    {!! Form::label('provider_name', '供货商:') !!}
    {!! Form::text('provider_name', null, ['class' => 'form-control']) !!}
</div>

<!-- Number Field -->
<div class="form-group col-sm-6">
    {!! Form::label('number', '数量:') !!}
    {!! Form::text('number', isset($goods)?$goods->number:0, ['class' => 'form-control']) !!}
</div>

<!-- Market Price Field -->
<div class="form-group col-sm-6">
    {!! Form::label('market_price', '市场价:') !!}
    {!! Form::text('market_price', isset($goods)?$goods->market_price:'0.00', ['class' => 'form-control']) !!}
</div>

<!-- Sale Price Field -->
<div class="form-group col-sm-6">
    {!! Form::label('sale_price', '优惠价:') !!}
    {!! Form::text('sale_price', isset($goods)?$goods->sale_price:'0.00', ['class' => 'form-control']) !!}
</div>

<!-- Unit Field -->
<div class="form-group col-sm-6">
    {!! Form::label('unit', '单位:') !!}
    {!! Form::text('unit', isset($goods)?$goods->unit:'个', ['class' => 'form-control']) !!}
</div>

<!-- Sale Start Date Field -->
<div class="form-group col-sm-6">
    {!! Form::label('sale_start_date', '销售开始时间:') !!}
    {!! Form::text('sale_start_date', isset($goods)?$goods->sale_start_date:date('Y-m-d H:i:s'), ['class' => 'form-control']) !!}
</div>

<!-- Sale End Date Field -->
<div class="form-group col-sm-6">
    {!! Form::label('sale_end_date', '销售结束时间:') !!}
    {!! Form::text('sale_end_date', isset($goods)?$goods->sale_end_date:date('2020-01-01 H:i:s',time()+3600*24*60), ['class' => 'form-control']) !!}
</div>

<!-- Is On Sale Field -->
<div class="form-group col-sm-6">
    {!! Form::label('is_on_sale', '是否销售:') !!}
    {!! Form::select('is_on_sale', ['1' => '是', '0' => '否'], isset($goods)?$goods->is_on_sale:1, ['class' => 'form-control']) !!}
</div>

<!-- Is Best Field -->
<div class="form-group col-sm-6">
    {!! Form::label('is_best', '是否佳品:') !!}
    {!! Form::select('is_best', ['1' => '是', '0' => '否'], isset($goods)?$goods->is_best:0, ['class' => 'form-control']) !!}
</div>

<!-- Is New Field -->
<div class="form-group col-sm-6">
    {!! Form::label('is_new', '是否新品:') !!}
    {!! Form::select('is_new', ['1' => '是', '0' => '否'], isset($goods)?$goods->is_new:0, ['class' => 'form-control']) !!}
</div>

<!-- Is Hot Field -->
<div class="form-group col-sm-6">
    {!! Form::label('is_hot', '是否热卖:') !!}
    {!! Form::select('is_hot', ['1' => '是', '0' => '否'], isset($goods)?$goods->is_hot:0, ['class' => 'form-control']) !!}
</div>

<div class="form-group col-sm-6">
    {!! Form::label('is_timely_sort', '是否及时分拣:') !!}
    {!! Form::select('is_timely_sort', ['1' => '是', '0' => '否'], isset($goods)?$goods->is_timely_sort:0, ['class' => 'form-control']) !!}
</div>

<!-- Sort Field -->
<div class="form-group col-sm-6">
    {!! Form::label('sort', '每日可购买数(0为不限制)') !!}
    {!! Form::text('day_buy_number', isset($goods)?$goods->day_buy_number:0, ['class' => 'form-control']) !!}
</div>

<div class="form-group col-sm-6">
    {!! Form::label('sort', '排序值(越小越靠前):') !!}
    {!! Form::text('sort', isset($goods)?$goods->sort:100, ['class' => 'form-control']) !!}
</div>

<!-- Desc Field -->
<div class="form-group col-sm-12 col-lg-12">
    {!! Form::label('desc', '描述:') !!}
    {!! Form::textarea('desc', null, ['class' => 'form-control']) !!}
</div>

<!-- Image Field -->
<div class="form-group col-sm-6">
    {!! Form::label('image', '封面(330*330):') !!}
    {!! Form::file('image') !!}
    @if(isset($goods))
        @mpic($goods->image)
    @endif
</div>
<br>

<div class="form-group col-sm-12">
    {!! Form::button('添加属性', ['class' => 'add-attribute btn btn-primary']) !!}
</div>
@if(isset($goods))
    @foreach($goods->attributesByStatus as $attribute)
    <div class="form-group col-sm-12 attribute-div">
        <input type="hidden" name="has_attribute[]" value="{{$attribute->id}}">
        属性名:<input name="attribute_{{$attribute->id}}_name" value="{{$attribute->name}}" type="text">
        市场价:<input name="attribute_{{$attribute->id}}_market_price" value="{{ $attribute->market_price }}" type="text">
        优惠价:<input name="attribute_{{$attribute->id}}_sale_price" value="{{ $attribute->sale_price }}" type="text">
        库存数:<input name="attribute_{{$attribute->id}}_number" value="{{ $attribute->number }}" type="text">
        每日可购买数(0为不限制):<input name="attribute_{{$attribute->id}}_day_buy_number" value="{{ $attribute->day_buy_number }}" type="text">
        销售量:<input name="attribute_{{$attribute->id}}_sales_count" value="{{ $attribute->sales_count }}" type="text">
        <button type="button" class="btn btn-danger del_attribute">删除</button>
    </div>
    @endforeach
@endif
<div id="attribute-dev">

</div>

<div class="form-group col-sm-12">
    {!! Form::button('添加轮播图(750*600)', ['class' => 'add-slideshow btn btn-primary']) !!}
    <div id="slideshow_pics">
        @if(isset($goods))
            @foreach($goods->slideshow as $content)
                <div class="form-group col-sm-12 pic-slideshow">
                    @mpic($content->url)
                    <button type="button" class="btn btn-danger del_slideshow">删除</button>
                    <button type="button" class="btn add-slideshow-next">添加</button>
                </div>
            @endforeach
        @endif
    </div>
</div>
<div class="form-group col-sm-12">
    {!! Form::button('添加详情图(750*任意)', ['class' => 'add-pic btn btn-primary']) !!}
    <div id="content_pics">
        @if(isset($goods))
            @foreach($goods->contents as $content)
                <div class="form-group col-sm-12 pic-div">
                    @mpic($content->url)
                    <input type="hidden" name="content_images[]" value="{!! $content->url !!}">
                    <button type="button" class="btn btn-danger del_pic">删除</button>
                    <button type="button" class="btn add-pic-next">添加</button>
                </div>
            @endforeach
        @endif
    </div>
</div>
<div class="clearfix"></div>

<!-- Submit Field -->
<div class="form-group col-sm-12">
    {!! Form::submit('保存', ['class' => 'btn btn-primary']) !!}
    <a href="{!! route('goods.index') !!}" class="btn btn-default">取消</a>
</div>

@section('scripts')
    <script>
        var bu ='<div class="form-group col-sm-12 pic-div"><input name="content_images[]" type="file" class="content_images"> <button type="button" class="btn btn-danger del_pic">删除</button> <button type="button" class="btn add-pic-next">添加</button></div>';               // 以 HTML 创建新元素
        var lb ='<div class="form-group col-sm-12 pic-slideshow"><input name="slideshow_images[]" type="file" class="slideshow_images"> <button type="button" class="btn btn-danger del_slideshow">删除</button>  <button type="button" class="btn add-slideshow-next">添加</button></div>';               // 以 HTML 创建新元素
        var at ='<div class="form-group col-sm-12 attribute-div">属性名:<input name="attribute_name[]" type="text"> 市场价:<input name="attribute_market_price[]" type="text"> 优惠价:<input name="attribute_sale_price[]" type="text"> 库存量:<input name="attribute_number[]" type="text">每日可购买数(0为不限制):<input name="attribute_day_buy_number[]" value="0" type="text">销售量:<input name="attribute_sales_count[]" value="0" type="text"> <button type="button" class="btn btn-danger del_attribute">删除</button></div>';               // 以 HTML 创建新元素

        $('.add-pic').click(function () {
            $('#content_pics').append(bu);
        });

        $(document).on("click", ".add-pic-next", function () {
            $(this).closest('.pic-div').before(bu);
        });

        $('.add-slideshow').click(function () {
            $('#slideshow_pics').append(lb)
        });

        $(document).on("click", ".add-slideshow-next", function () {
            $(this).closest('.pic-slideshow').before(lb)
        });

        $('.add-attribute').click(function () {
            $('#attribute-dev').append(at);
        });

        $('div').delegate('.del_attribute', 'click',function () {
            this.closest('.attribute-div').remove();
        });
        $('div').delegate('.del_pic', 'click',function () {
            this.closest('.pic-div').remove();
        });
        $('div').delegate('.del_slideshow', 'click',function () {
            this.closest('.pic-slideshow').remove();
        });
    </script>
@endsection
